<template>
  <div class="mainos">
    <div class="main_spac1 paddingBottom5">
      <div class="main_white padding10 paddingBottom20">
        <div class="main_crumbs boxdq">
          <div class="main_crumbs_l">
            <a href="javascript:;" @click="$router.back(-1)">
              <i class="el-icon-arrow-down"></i>返回
            </a>
            <em>|</em>
            <span>查看</span>
          </div>
          <div class="main_crumbs_rt">
            <el-button v-repeatClick class="marginLeft5">打印</el-button>
            <el-button v-repeatClick class="marginLeft5" @click="export_de"
              >导出</el-button
            >
          </div>
        </div>
        <div class="main_tile boxdq marginTop10">
          <div class="main_tile_l marginLeft0"><em></em>基础信息</div>
        </div>
        <div class="main_xq" v-if="info.info.type == 1">
          <ul class="boxha">
            <li>
              采购单号：<span>{{ info.info.related_order_sn }}</span>
            </li>
            <li>
              采购日期：<span>{{
                info.info.purchase_time
                  ? parseTime(info.info.purchase_time, "{y}-{m}-{d}")
                  : ""
              }}</span>
            </li>
            <li>
              采购方式：<span>{{ info.modeList[info.info.mode] }}</span>
            </li>
            <li>
              采购员/供应商：<span>{{
                info.info.mode == 1
                  ? info.buyer[info.info.buyer_id]
                  : info.supplier[info.info.supplier_id]
              }}</span>
            </li>
            <li>
              对账单号：<span>{{ info.info.order_sn }}</span>
            </li>
            <li>
              采购金额：<span>{{ info.info.money_all }}</span>
            </li>
            <li>
              对账金额：<span>{{ info.info.account_money }}</span>
            </li>
            <li>
              差异金额：<span>{{ info.info.diff_money }}</span>
            </li>
            <li>
              对账状态：<span>{{
                info.account_status_list[info.info.account_status]
              }}</span>
            </li>
            <li>
              结算状态：<span>{{ info.statusList[info.info.status] }}</span>
            </li>
            <li class="main_w100">
              备注：<span>{{ info.remark }}</span>
            </li>
          </ul>
        </div>
        <div class="main_xq" v-else>
          <ul class="boxha">
            <li>
              退货单号：<span>{{ info.info.order_sn }}</span>
            </li>
            <li>
              采购方式：<span>{{ info.modeList[info.info.mode] }}</span>
            </li>
            <li>
              采购员/供应商：<span>{{
                info.info.mode == 1
                  ? info.buyer[info.info.buyer_id]
                  : info.supplier[info.info.supplier_id]
              }}</span>
            </li>
            <li>
              对账单号：<span>{{ info.info.order_sn }}</span>
            </li>
            <li>
              退货金额：<span>{{ info.info.money_all }}</span>
            </li>
            <li>
              对账金额：<span>{{ info.info.account_money }}</span>
            </li>
            <li>
              差异金额：<span>{{ info.info.diff_money }}</span>
            </li>
            <li>
              对账状态：<span>{{
                info.account_status_list[info.info.account_status]
              }}</span>
            </li>
            <li>
              结算状态：<span>{{ info.statusList[info.info.status] }}</span>
            </li>
            <li class="main_w100">
              备注：<span>{{ info.info.remark }}</span>
            </li>
          </ul>
        </div>
        <div class="main_tile boxdq marginTop10">
          <div class="main_tile_l marginLeft0"><em></em>商品详情</div>
          <div class="mainos_tile_r">合计：{{ info.info.money_all }}元</div>
        </div>
        <div class="main_table marginTop0" v-if="info.info.type == 1">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="info.info.account_statement_list"
            element-loading-text="加载中"
            fit
            highlight-current-row
          >
            <el-table-column label="序号" prop="userId">
              <template slot-scope="scope">{{ scope.$index + 1 }}</template>
            </el-table-column>
            <el-table-column
              label="商品名称"
              width="150"
              prop="name"
              class-name="main_hei"
            >
              <template slot-scope="scope"
                >{{ scope.row.goods.name }}【{{
                  scope.row.goods_spu.spu_name.title
                }}】</template
              >
            </el-table-column>
            <el-table-column
              label="单位"
              prop="goods_spu.spu_unit.title"
              class-name="main_hei"
            />
            <el-table-column
              label="采购数量"
              width="150"
              prop="num"
              class-name="main_hei"
            />
            <el-table-column
              label="采购单价"
              width="150"
              prop="price"
              class-name="main_hei"
            />
            <el-table-column
              label="采购金额"
              width="150"
              prop="price"
              class-name="main_hei"
            >
              <template slot-scope="scope">{{
                (
                  parseFloat(scope.row.price) * parseFloat(scope.row.num)
                ).toFixed(2)
              }}</template>
            </el-table-column>
            <el-table-column
              label="对账数量"
              width="150"
              prop="account_num"
              class-name="main_hei"
            />
            <el-table-column
              label="对账单价"
              prop="account_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="对账金额"
              prop=""
              width="150"
              class-name="main_hei"
            >
              <template slot-scope="scope">
                {{
                  parseFloat(scope.row.account_num) *
                  parseFloat(scope.row.account_price)
                    ? (
                        parseFloat(scope.row.account_num) *
                        parseFloat(scope.row.account_price)
                      ).toFixed(2)
                    : 0.0
                }}
              </template>
            </el-table-column>
            <el-table-column
              label="差异数量"
              prop="diff_num"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异单价"
              prop="diff_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异金额"
              prop="diff_money"
              width="150"
              class-name="main_hei"
            />
            <el-table-column label="备注" prop="remark" class-name="main_hei" />
          </el-table>
        </div>
        <div class="main_table marginTop0" v-else>
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="info.info.account_statement_list"
            element-loading-text="加载中"
            fit
            highlight-current-row
          >
            <el-table-column label="序号" prop="userId">
              <template slot-scope="scope">{{ scope.$index + 1 }}</template>
            </el-table-column>
            <el-table-column
              label="商品名称"
              width="150"
              prop="name"
              class-name="main_hei"
            >
              <template slot-scope="scope"
                >{{ scope.row.goods.name }}【{{
                  scope.row.goods_spu.spu_name.title
                }}】</template
              >
            </el-table-column>
            <el-table-column
              label="单位"
              prop="goods_spu.spu_unit.title"
              class-name="main_hei"
            />
            <el-table-column
              label="退货数量"
              width="150"
              prop="num"
              class-name="main_hei"
            />
            <el-table-column
              label="退货单价"
              width="150"
              prop="account_num"
              class-name="main_hei"
            />
            <el-table-column
              label="退货金额"
              width="150"
              prop="price"
              class-name="main_hei"
            >
              <template slot-scope="scope">{{
                (
                  parseFloat(scope.row.price) * parseFloat(scope.row.num)
                ).toFixed(2)
              }}</template>
            </el-table-column>
            <el-table-column
              label="对账数量"
              width="150"
              prop="account_num"
              class-name="main_hei"
            />
            <el-table-column
              label="对账单价"
              prop="account_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="对账金额"
              prop="remark"
              width="150"
              class-name="main_hei"
            >
              <template slot-scope="scope">
                {{
                  parseFloat(scope.row.account_num) *
                  parseFloat(scope.row.account_price)
                    ? (
                        parseFloat(scope.row.account_num) *
                        parseFloat(scope.row.account_price)
                      ).toFixed(2)
                    : 0.0
                }}
              </template>
            </el-table-column>
            <el-table-column
              label="差异数量"
              prop="diff_num"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异单价"
              prop="diff_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异金额"
              prop="diff_money"
              width="150"
              class-name="main_hei"
            />
            <el-table-column label="备注" prop="remark" class-name="main_hei" />
          </el-table>
        </div>
        <div class="main_tile boxdq marginTop20">
          <div class="main_tile_l marginLeft0"><em></em>生命周期</div>
        </div>
        <div class="main_table marginTop0">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="info.logs"
            element-loading-text="加载中"
            fit
            highlight-current-row
          >
            <el-table-column
              label="管理员"
              prop="admin.name"
              class-name="main_hei"
            />
            <el-table-column
              label="操作"
              prop="operate.name"
              class-name="main_hei"
            />
            <el-table-column label="内容" prop="content" class-name="main_hei">
              <template slot-scope="scope">
                <div
                  v-for="(content, index) in scope.row.content"
                  :key="index"
                  class="marginTop5 marginBottom5"
                >
                  {{ content }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="IP" prop="ip" class-name="main_hei" />
            <el-table-column
              label="时间"
              prop="created_at"
              class-name="main_hei"
            >
              <template slot-scope="scope">{{
                parseTime(scope.row.created_at, "{y}-{m}-{d}")
              }}</template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  account_info,
  export_account_balance,
} from "@/api/financial/financialRecharge";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";

export default {
  computed: {
    total() {
      let dz = 0;
      this.info.info.account_statement_list.forEach((e) => {
        dz += parseFloat(e.account_price) * parseFloat(e.account_num);
      });
      dz = dz ? dz.toFixed(2) : "0.00";
      return { dz };
    },
  },
  components: {},
  data() {
    return {
      // 时间
      parseTime,
      // 基本信息
      info: {
        info: {
          money: 0,
          created_at: "2000-01-01",
          type: 0,
          status: 0,
          mode: 0,
          account_statement_list: [],
        },
        buyer: ["未分拣"],
        modeList: ["未分拣"],
        supplier: ["未分拣"],
        typeList: ["未分拣"],
        account_status_list: ["未分拣"],
        statusList: ["未分拣"],
      },
      listLoading: false,
      // id
      id: this.$route.params.id,
    };
  },
  created() {
    // 基本信息
    this.account_info();
  },
  methods: {
    // 基本信息
    account_info() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      account_info(data).then((res) => {
        if (res.errcode == 0) {
          this.info = res.data;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 导出
    export_de() {
      if (!this.id) {
        return;
      }
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      export_account_balance(data)
        .then((res) => {
          const link = document.createElement("a");
          let blob = new Blob([res], { type: "application/vnd.ms-excel" });
          link.style.display = "none";
          link.href = URL.createObjectURL(blob);
          link.download = "采购结算";
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
        .catch(() => {
          this.$message.error("导出失败");
        });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainos {
  .main_tile {
    .mainos_tile_r {
      color: $colour_red;
      font-size: $font_14;
    }
  }
  .mainor_ex {
    position: fixed;
    width: 220px;
    height: 100%;
    background: $white;
    box-shadow: 0 6px 10px rgba(0, 21, 41, 0.08);
    top: 0;
    right: 0;
    z-index: 9999;
    transition: all 0.5s;
    transform: translate3d(100%, 0, 0);
    &.on {
      transform: translate3d(0, 0, 0);
    }
    .mainor_exb {
      position: absolute;
      width: 100%;
      height: calc(100% - 60px);
      overflow-y: auto;
      h3 {
        font-size: $font_16;
        color: $colour_18;
        height: 50px;
        line-height: 50px;
        border-bottom: 1px solid $colour_e6;
        padding-left: 20px;
      }
      .mainor_exb_an {
        padding-left: 20px;
        margin-top: 15px;
        /deep/.el-checkbox {
          display: block;
          margin-top: 15px;
          margin-bottom: 15px;
        }
      }
    }
    .mainor_exb_b {
      position: absolute;
      bottom: 0;
      width: 100%;
      border-top: 1px solid $colour_e6;
      height: 55px;
      text-align: center;
      /deep/.el-button--default {
        margin-top: 12px;
        border-color: $subActive;
        color: $menuText;
        &:hover {
          border-color: $menuActiveText;
          color: $menuActiveText;
        }
      }
    }
  }
}
</style>
